const path = require('path')
// 自动生成html文件
const HtmlWebpackPlugin = require('html-webpack-plugin');
// 自动清除dist目录下文件
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
    mode: 'development',
    entry: {
      // 入口文件
      main: './src/main.js',
      index: './src/index.js'
    },
    output: {
      // 出口文件
      path: path.join(__dirname,'dist'),
      filename: '[name].js'
    },
    module: {
      rules: [
        // css资源
        {
          test: /\.css$/,
          use: ['style-loader','css-loader']
        },{
          test: /\.less$/,
          use: ['style-loader','css-loader','less-loader']
        },{
          // 图片资源
          test: /\.png|jpg|gif|svg$/,
          use: [{
            loader: 'url-loader',
            options: {
              limit: 13003,
              name: 'img/[name].[hash:8].[ext]',
              // 关闭es模块，使用commonjs
              esModule: false
            }
          }],
          type: 'javascript/auto'
        },{
          // es6转换为es5
          test: /\.js$/,
          exclude: /(node_modules|bower_components)/,
          use: {
            loader:'babel-loader',
            options: {
              presets: ['@babel/preset-env']
            }
          }
        }
      ]
    },
    plugins: [
      new CleanWebpackPlugin(),
      new HtmlWebpackPlugin()
    ]
}